package com.cargohu.aishouyu.operation.controller;

import com.cargohu.aishouyu.common.CommonConstants;
import com.cargohu.aishouyu.framework.page.Paging;
import com.cargohu.aishouyu.framework.response.ApiResult;
import com.cargohu.aishouyu.operation.dto.AppVersionAddDTO;
import com.cargohu.aishouyu.operation.dto.AppVersionUpdateDTO;
import com.cargohu.aishouyu.operation.req.AppVersionRequest;
import com.cargohu.aishouyu.operation.resp.AppVersionDetailVo;
import com.cargohu.aishouyu.operation.resp.AppVersionResponse;
import com.cargohu.aishouyu.operation.service.AppVersionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * APP版本信息 控制器
 *
 * @author yww
 * @since 2023-11-29
 */
@Slf4j
@RestController
@RequestMapping(CommonConstants.API_ADMIN_PATH+"/app-version")
@Tag(name = "APP版本管理")
public class AppVersionController {

    @Autowired
    private AppVersionService appVersionService;

    /**
     * 添加APP版本信息
     *
     * @param appVersionAddDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    @Operation(summary = "添加APP版本信息")
    public ApiResult addAppVersion(@Valid @RequestBody AppVersionAddDTO appVersionAddDTO) throws Exception {
        boolean flag = appVersionService.addAppVersion(appVersionAddDTO);
        return ApiResult.result(flag);
    }

    /**
     * 修改APP版本信息
     *
     * @param appVersionUpdateDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    @Operation(summary = "修改APP版本信息")
    public ApiResult updateAppVersion(@Valid @RequestBody AppVersionUpdateDTO appVersionUpdateDTO) throws Exception {
        boolean flag = appVersionService.updateAppVersion(appVersionUpdateDTO);
        return ApiResult.result(flag);
    }

    /**
     * 删除APP版本信息
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除APP版本信息")
    public ApiResult deleteAppVersion(@PathVariable Long id) throws Exception {
        boolean flag = appVersionService.deleteAppVersion(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取APP版本信息详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/get/{id}")
    @Operation(summary = "APP版本信息详情")
    public ApiResult<AppVersionDetailVo> getAppVersion(@PathVariable Long id) throws Exception {
        AppVersionDetailVo appVersionDetailVo = appVersionService.getAppVersionById(id);
        return ApiResult.success(appVersionDetailVo);
    }

    /**
     * APP版本信息分页列表
     *
     * @param appVersionRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/page")
    @Operation(summary = "APP版本信息分页列表")
    public ApiResult<AppVersionResponse> getAppVersionList(@Valid @RequestBody AppVersionRequest appVersionRequest) throws Exception {
        Paging<AppVersionResponse> paging = appVersionService.getAppVersionList(appVersionRequest);
        return ApiResult.success(paging);
    }

}
